﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using wanzheng;
namespace MS_UI
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }

 #region 打开窗体
        private void OpenWindow(Form Frm)
        {

            //不能为顶级窗体
            Frm.TopLevel = false;
            //窗体边框样式
            Frm.FormBorderStyle = FormBorderStyle.None;
            //指定位置和控件停靠方式
            Frm.Dock = DockStyle.Fill;

            //获取或控制控件的父容器
            Frm.Parent = this.MainPanel;
            //打开窗体
            Frm.Show();


        }
#endregion 



        #region 关闭窗体
        private bool CloseWindow(string FrmName)
        {
           
            foreach (Control ct in this.MainPanel.Controls)
            {
                if (ct is Form)
                {

                    Form Frm = (Form)ct;

                    if (Frm.Name == FrmName)
                    {
                        return true;
                    }
                    else
                    { 
                    
                    Frm.Close();
                    }

                }
            }
            return false;
        }




        #endregion

        private void btn_View_Click(object sender, EventArgs e)
        {
            if (CloseWindow("FrmView") == false)
            {

                OpenWindow(new FrmView());

                //给抬头标题传标题
                this.IbI_Title.Text = ((Button)sender).Text;

                //修改按钮颜色
                BackColorSet(((Button)sender).Text);

            }
        }

        private void btn_ParamSet_Click(object sender, EventArgs e)
        {
            if (CloseWindow("FrmParamSet") == false)
            {

                OpenWindow(new FrmParamSet());
                //给抬头标题传标题
                this.IbI_Title.Text = ((Button)sender).Text;

                BackColorSet(((Button)sender).Text);
            }
        }

        private void btn_Trend_Click(object sender, EventArgs e)
        {
            if (CloseWindow("FrmTrend") == false)
            {

                OpenWindow(new FrmTrend());
                //给抬头标题传标题
                this.IbI_Title.Text = ((Button)sender).Text;

                BackColorSet(((Button)sender).Text);
            }
        }

        private void btn_Alarm_Click(object sender, EventArgs e)
        {
            if (CloseWindow("FrmAlarm") == false)
            {

                OpenWindow(new FrmAlarm());

                //给抬头标题传标题
                this.IbI_Title.Text = ((Button)sender).Text;

                BackColorSet(((Button)sender).Text);
            }
        }

        private void btn_Report_Click(object sender, EventArgs e)
        {
            if (CloseWindow("FrmReport") == false)
            {

                OpenWindow(new FrmReport());

                //给抬头标题传标题
                this.IbI_Title.Text = ((Button)sender).Text;

                BackColorSet(((Button)sender).Text);
            }
        }

        private void btn_HardwareConfig_Click(object sender, EventArgs e)
        {
            if (CloseWindow("FrmHardwareConfig") == false)
            {

                OpenWindow(new FrmHardwareConfig());

                //给抬头标题传标题
                this.IbI_Title.Text = ((Button)sender).Text;

                BackColorSet(((Button)sender).Text);
            }
        }

        private void btn_Exit_Click(object sender, EventArgs e)
        {
           Application.Exit();
        }

        private void BackColorSet(String item)
        {

            this.btn_View.BackColor = Color.FromArgb(20,50, 60);
            this.btn_ParamSet.BackColor = Color.FromArgb(11, 115, 163);
            this.btn_Trend.BackColor = Color.FromArgb(11, 115, 163);
            this.btn_Alarm.BackColor = Color.FromArgb(11, 115, 163);
            this.btn_Report.BackColor = Color.FromArgb(11, 115, 163);
            this.btn_HardwareConfig.BackColor = Color.FromArgb(11, 115, 163);

            switch (item)
            {
                case "控制流程":
                    this.btn_View.BackColor = Color.FromArgb(60, 179, 113);
                    break;

                case "参数设置":
                    this.btn_ParamSet.BackColor = Color.FromArgb(30, 50, 77);
                    break;

                case "趋势图":
                    this.btn_Trend.BackColor = Color.FromArgb(60, 179, 113);
                    break;

                case "故障报警":
                    this.btn_Alarm.BackColor = Color.FromArgb(60, 179, 113);
                    break;

                case "数据报表":
                    this.btn_Report.BackColor = Color.FromArgb(60, 179, 113);
                    break;

                case "硬件组态":
                    this.btn_HardwareConfig.BackColor = Color.FromArgb(60, 179, 113);
                    break;


            }


        }




    }
}
